// Magic Software, Inc.
// http://www.magic-software.com
// Copyright (c) 2000, All Rights Reserved
//
// Source code from Magic Software is supplied under the terms of a license
// agreement and may not be copied or disclosed except in accordance with the
// terms of that agreement.  The various license agreements may be found at
// the Magic Software web site.  This file is subject to the license
//
// FREE SOURCE CODE
// http://www.magic-software.com/License/free.pdf

#ifndef MGCMINIMIZE1D_H
#define MGCMINIMIZE1D_H

#include "MgcMath.h"


class MgcMinimize1D
{
public:
    typedef MgcReal (*Function)(MgcReal,void*);

    MgcMinimize1D (Function oF, unsigned int uiMaxLevel,
        unsigned int uiMaxBracket, void* pvUserData = 0);

    ~MgcMinimize1D ();

    unsigned int& MaxLevel ();
    unsigned int& MaxBracket ();
    void*& UserData ();

    void GetMinimum (MgcReal fT0, MgcReal fT1, MgcReal fTInitial,
        MgcReal& rfTMin, MgcReal& rfFMin);

protected:
    Function m_oF;
    unsigned int m_uiMaxLevel, m_uiMaxBracket;
    MgcReal m_fTMin, m_fFMin;
    void* m_pvUserData;

    void GetMinimum (MgcReal fT0, MgcReal fF0, MgcReal fT1, MgcReal fF1,
        unsigned int uiLevel);

    void GetMinimum (MgcReal fT0, MgcReal fF0, MgcReal fTm, MgcReal fFm,
        MgcReal fT1, MgcReal fF1, unsigned int uiLevel);

    void GetBracketedMinimum (MgcReal fT0, MgcReal fF0, MgcReal fTm,
        MgcReal fFm, MgcReal fT1, MgcReal fF1, unsigned int uiLevel);
};

//----------------------------------------------------------------------------
inline MgcMinimize1D::~MgcMinimize1D ()
{
}
//----------------------------------------------------------------------------
inline unsigned int& MgcMinimize1D::MaxLevel ()
{
    return m_uiMaxLevel;
}
//----------------------------------------------------------------------------
inline unsigned int& MgcMinimize1D::MaxBracket ()
{
    return m_uiMaxBracket;
}
//----------------------------------------------------------------------------
inline void*& MgcMinimize1D::UserData ()
{
    return m_pvUserData;
}
//----------------------------------------------------------------------------

#endif
